package com.copy;

import java.io.*;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-28
 */
public class PictureCopy {
    public static void main(String[] args) {
        String fileParent = "D:\\CScode\\code\\java_code\\2024\\t0728\\src\\com";
        String fileChild1 = "picture.jpg";
        String fileChild2 = "copy.jpg";
        File fileName = new File(fileParent, fileChild1);
        File fileDest = new File(fileParent, fileChild2);
        BufferedInputStream bufIn = null;
        BufferedOutputStream bufOut = null;

        try {
            bufIn = new BufferedInputStream(new FileInputStream(fileName));
            bufOut = new BufferedOutputStream(new FileOutputStream(fileDest));
            byte[] str = new byte[1024];
            int readLen = 0;
            while ((readLen = bufIn.read(str)) != -1) {
                bufOut.write(str, 0, readLen);
            }
            System.out.println(fileName.getName() + "图片拷贝成功");
        } catch (IOException e) {
            System.out.println("流创建失败");
            e.printStackTrace();
        } finally {
            try {
                if (bufIn != null) {
                    bufIn.close();
                }
                if (bufOut != null) {
                    bufOut.close();
                }
            } catch (IOException e) {
                System.out.println("流关闭失败");
                e.printStackTrace();
            }
        }
    }
}
